<template>
  <div class="hy-message-box" v-if="modelValue">
    <div class="hy-message-box-cover"></div>
    <div class="hy-message-box-content flex">
      <div class="hy-message-box-close" @click="onClose">
        <i class="iconfont flex-center icon-close"></i>
      </div>
      <div class="hy-message-box-text flex1">
        <slot></slot>
      </div>
      <div class="hy-message-box-botton flex-between">
        <button class="hy-message-box-botton-confirm flex1" @click="onConfirm" style="background-color: #20a0ff">
          确认
        </button>
        <button
          type="reset"
          class="hy-message-box-botton-cancel flex1"
          @click="onCancel"
          style="background-color: #666666"
        >
          取消
        </button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  props: {
    modelValue: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue', 'on-confirm', 'on-cancel', 'on-close'],
  setup(props, { emit }) {
    const onConfirm = () => {
      emit('on-confirm');
      emit('update:modelValue', false);
    };

    const onCancel = () => {
      emit('on-cancel');
      emit('update:modelValue', false);
    };

    const onClose = () => {
      emit('on-close');
      emit('update:modelValue', false);
    };

    return {
      onConfirm,
      onCancel,
      onClose
    };
  }
});
</script>

<style lang="less" scoped>
.hy-message-box {
  position: fixed;
  z-index: 2;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  &-cover {
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.5);
  }
  &-content {
    position: absolute;
    width: 260px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: @white-color;
    border-radius: 4px;
    flex-direction: column;
    box-shadow: 0 0 10px @shadown-color;
  }
  &-close {
    position: absolute;
    right: 10px;
    top: 10px;
    .iconfont {
      font-size: 20px;
    }
    &:hover {
      background-color: @background-sub-color;
    }
  }
  &-text {
    font-size: 15px;
    padding: 34px 20px 20px;
  }
  &-botton {
    height: 36px;
    border-top: 1px solid @border-color;
    button {
      border: none;
      background-color: transparent;
      font-size: 15px;
      text-align: center;
      height: 100%;
      line-height: 36px;
      cursor: pointer;
      &:hover {
        background-color: @background-sub-color;
      }
    }
    &-cancel {
      color: @text-sub-color;
    }
  }
}
.hy-message-box-content {
  width: 560px;
  height: 320px;
  background-color: #fff;
  box-shadow: 2px 2px 20px 1px;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
}
.hy-message-box-botton-confirm {
  background: #409eff;
}
</style>
